<!DOCTYPE html>
<html>

<head>
    <title>修改密码·车队管理系统</title>
    {include file="common/header"/}
        <el-main>
        <el-card class="box-card" shadow="never">
            <div slot="header" class="clearfix">
                <span>修改我的密码</span>
            </div>
            <el-form model ='form' status-icon :rules="rules" ref="form" label-width="100px">
                <el-form-item label="原密码" prop="oldPassword">
                    <el-input show-password v-model="form.oldPassword" placeholder="请输入原密码"></el-input>
                </el-form-item>
                <el-form-item label="新密码" prop="newPassword">
                    <el-input show-password v-model="form.newPassword" placeholder="请输入新密码"></el-input>
                </el-form-item>
                <el-form-item label="新密码" prop="checkPassword">
                    <el-input show-password v-model="form.checkPassword" placeholder="请确认新密码"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="onSubmit">修改密码</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        </el-main>
    {include file="common/footer"/}
<script>
    new Vue({
        el: '#app',
        data() {
            return {
                form: {
                    oldPassword: "",
                    newPassword: "",
                    checkPassword: "",
                },
                rules:{
                },
            username : "",
            }
        },
        mounted () {
            this.abcd();
        },

        methods: {
            onSubmit(){
                var that = this;
                that.$refs['form'].validate((valid) => {
                    if (!valid) {
                        that.$message.error('仔细检查检查，是不是有个地方写得不对？');
                        return;
                    }
                    if (that.form.newPassword != that.form.checkPassword) {
                        that.$message.error('两次密码输入不一致，请确认');
                        return;
                    }
                    axios.post('user/changepswd', Object.assign({}, PostBase, {
                        oldPassword: that.form.oldPassword,
                        newPassword: that.form.newPassword,
                    }))
                        .then(function (response) {
                            if (response.data.code == CODE_SUCCESS) {
                                that.$message({
                                    message: '密码修改成功,正在跳转中',
                                    type: 'success'
                                });
                                setTimeout(function () {
                                    location.replace('/index');
                                }, 500);
                            } else {
                                that.$message.error(response.data.msg);
                            }
                        })
                        .catch(function (error) {
                            that.$message.error('服务器内部错误');
                            console.log(error);
                        });

                });
            },
            abcd(){
                var that = this;
                axios.post('user/getmyvalue')
                    .then(function (response)
                    {
                        that.username = response.data.data.name;
                    })

            },
            logOut() {
                var that = this;
                axios.post('user/logout', Object.assign({}, PostBase))
                    .then(function (response)
                    {
                        if (response.data.code == 200) {
                            that.$message({
                                message: '退出成功,正在跳转中',
                                type: 'success'
                            });
                            setTimeout(function () {
                                location.replace('');
                            }, 1000)
                        } else {
                            that.$message.error(response.data.msg);
                        }
                    })
                    .catch(function (error)
                    {
                        that.$message.error('tuichu失败，服务器内部错误');
                    })
                ;

            }
        }
    })
</script>

</html>